package com.weic.controller;

import com.weic.listener.MyListener;
import com.weic.pojo.Dept;
import com.weic.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value = "/dept")
public class DeptController {

    @Autowired
    DeptService deptService;

    @RequestMapping(value = "/getAll/{pageno}/{pagesize}")
    public @ResponseBody  List<Dept> getAll(@PathVariable("pageno") int pageno, @PathVariable("pagesize") int pagesize){
        return deptService.getAll(pageno ,pagesize);
    }

    @RequestMapping(value = "/deptPage.html")
    public ModelAndView deptPage(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("name","weic");
        session.setAttribute("age",18);
        return new ModelAndView("/deptPage");
    }

    @RequestMapping(value = "/onLine")
    public @ResponseBody String getOneLine(){
        String str = "当前在线人数："+ MyListener.online+" 人";
        return str;
    }
}
